package com.wv.api.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.wv.api.mapper.SysDeptDao;
import com.wv.api.service.ISysDeptService;
import com.wv.common.result.PageResponseResult;
import com.wv.model.system.condition.SysDeptCondition;
import com.wv.model.system.vo.SysDeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SysDeptServiceImpl implements ISysDeptService {

    @Autowired
    private SysDeptDao sysDeptDao;

    @Override
    public PageResponseResult getDeptList(SysDeptCondition sysDeptCondition) {
        PageHelper.startPage(sysDeptCondition.getPage(), sysDeptCondition.getSize());
        PageResponseResult build = PageResponseResult.builder()
                .total(sysDeptDao.selectCount(null))
                .build();
        List<SysDeptVo> collect = sysDeptDao.selectList(null).stream().map(sysDept -> {
            SysDeptVo sysDeptVo = new SysDeptVo();
            BeanUtil.copyProperties(sysDept, sysDeptVo);
            return sysDeptVo;
        }).collect(Collectors.toList());
        build.setData(collect);
        return build;
    }
}
